<?php
// 评论主题表

if (!$system['table']) {
    return $this->_return($system['return'], 'table参数不能为空');
}
if ($system['table'] == 'module') {
    if (!$system['module']) {
        return $this->_return($system['return'], 'module参数不能为空');
    }
    $comment = \Phpcmf\Service::L('cache')->get('app-comment-'.$system['site'], 'module', $system['module']);
} elseif ($system['table'] == 'form') {
    if (!$system['form']) {
        return $this->_return($system['return'], 'form参数不能为空');
    }
    $comment = \Phpcmf\Service::L('cache')->get('app-comment-'.$system['site'], 'form', $system['form']);
} elseif ($system['table'] == 'mform') {
    if (!$system['form']) {
        return $this->_return($system['return'], 'form参数不能为空');
    } elseif (!$system['module']) {
        return $this->_return($system['return'], 'module参数不能为空');
    }
    $comment = \Phpcmf\Service::L('cache')->get('app-comment-'.$system['site'], 'mform', $system['module'].'-'.$system['form']);
}

// 判断是否存在
if (!$comment || !$comment['use']) {
    return $this->_return($system['return'], "当前没有开启评论功能"); // 参数判断
}

if ($system['table'] == 'module') {
    $module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$system['module']);
    $comment_model = \Phpcmf\Service::M('Content', $system['module']);
    $comment_model->_init($system['module'], $system['site'], $module['share']);
} elseif ($system['table'] == 'form') {
    $form = \Phpcmf\Service::L('cache')->get('form-'.$system['site'], $system['form']);
    $comment_model = \Phpcmf\Service::M('form', 'comment')->_init($form, $system['form'], $system['site'], $comment);
} elseif ($system['table'] == 'mform') {
    $module = \Phpcmf\Service::L('cache')->get('module-'.$system['site'].'-'.$system['module']);
    $comment_model = \Phpcmf\Service::M('mform', 'comment')->_init($module, $system['form'], $system['site'], $comment);
}

if (!$param['id']) {
    return $this->_return($system['return'], 'id参数不能为空');
}

$index = $comment_model->get_comment_index(intval($param['id']));
if (!$index) {
    return $this->_return($system['return'], '主题内容不存在');
}

$index['config'] = $comment;


$data = [
    $index
];

// 存储缓存
$system['cache'] && $this->_save_cache_data($cache_name, [
    'data' => $data,
    'sql' => '',
    'total' => 0,
    'pages' => '',
    'pagesize' => 0,
    'page_used' => $this->_page_used,
    'page_urlrule' => $this->_page_urlrule,
], $system['cache']);

return $this->_return($system['return'], $data, '', 0, '', 0);